<template>
	<view>
		<view class="head">
			<view style="font-weight: bold; font-size: 40rpx;">我报名的活动</view>
		</view>

		<view class="staff">
			<view class="staff-em"></view>
			<view class="staff-text">活动列表</view>
		</view>

		<!-- <scroll-view scroll-y :style="'height:'+scrollH+'px;'"> -->
			<view v-if="activity_list_data.length" class="line-h-md">
				<block v-for="(item,index) in activity_list_data" :key="index">
					<view class="box">
						<view class="ml-2 mr-2 mt-2">
							<view class="contenttext"><text>活动名称：</text>{{item.activity_info.title}}({{item.fac_info.name}})</view>
							<view class="contenttext"><text>活动内容：</text>{{item.activity_info.content}}</view>
							<view class="contenttext"><text>创建时间：</text>{{item.activity_info.create_time}}</view>
							<view class="contenttext"><text>员工姓名：</text>{{item.name}}</view>
							<view class="contenttext"><text>报名时间：</text>{{item.create_time}}</view>
						</view>

						<view class="link">
							<view @click="details(index)">活动详情 >></view>
							<view @click="mange(index)">邀约客户 >></view>
							<view @click="my(index)">员工信息 >></view>
						</view>
					</view>
				</block>
			</view>
			<uni-load-more :status="status"/>
			
			<view style="width: 750rpx; height: 100rpx;"></view>
			
			<staff-tab-bar :pagePath="'/pages/staff/staff_joinactivitylist'" :activity_id="activity_id" :factory_id="factory_id" :staff_id="staff_id" />
			
			<view class="top" :style="{'display':(flag===true? 'block':'none')}">
				<uni-icons class="topc" type="arrowthinup" size="30" @click="top"></uni-icons>
			</view>
			
			<!-- <noMore /> -->
		<!-- </scroll-view> -->
	</view>

</template>

<script>
	import staffJoinActList from '../../components/staff/staff_joinactlist.vue'
	import uniLoadMore from '../../components/common/uni-load-more.vue'
	import uniIcons from '../../components/common/uni-icons/uni-icons.vue'
	import staffTabBar from '../../components/staff/staff_tabbar.vue'
	
	export default {
		components: {
			staffJoinActList,
			staffTabBar,
			uniLoadMore,
			uniIcons,
		},
		data() {
			return {
				scrollH: 100,
				factory_id: '',
				staff_id: '',
				activity_id: '',
				activity_list_data: [],
				activity_info: [],
				factory_info: [],
				index: 0,
				page: 1,
				status: 'more',
				flag: false,
			};
		},
		onLoad(e) {
			this.activity_id = e.activity_id
			this.factory_id = e.factory_id
			this.staff_id = e.staff_id
			this.$comm.appLogin(user_info=>{
				this.activity_list()
				this.get_scrollH()
			})
		},
		onPullDownRefresh() {
			this.loaddata()
		},
		onReachBottom() {
			this.activity_list()
		},
		methods: {
			//获取已参加的活动列表
			activity_list() {
				if (this.status == 'nomore') {
					return
				}
				this.$comm.request({
					url: 'api/staff_activity_list',
					method: 'GET',
					data: {
						page: this.page++
					},
					success: res => {
						console.log(res,'api/staff_activity_list')
						var list = res.data.result.fac_list;
						this.activity_list_data = this.activity_list_data.concat(list)
						if (list.length < 10) {
							this.status = 'nomore'
						}
					}
				});
			},
			
			loaddata() {
				this.page = 1
				this.status = 'more'
				this.activity_list_data = []
				this.activity_list()
				setTimeout(function() {
					uni.stopPullDownRefresh();
				}, 1000);
			},
			
			//回到顶部
			top() {
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 300
				});
			},
			onPageScroll(e) { //根据距离顶部距离是否显示回到顶部按钮
				if (e.scrollTop > 600) { //当距离大于600时显示回到顶部按钮
					this.flag = true
				} else { //当距离小于600时显示回到顶部按钮
					this.flag = false
				}
			},
			
			get_scrollH() {
				//获取可视区域高度
				uni.getSystemInfo({
					success: (res) => {
						this.scrollH = res.windowHeight - uni.upx2px(183)
						// console.log(res.windowHeight, '可视区域高度',this.scrollH)
					}
				})
			},
			
			//打开详情页面
			details(index) {
				uni.navigateTo({
					url: '../index/index?activity_id=' + 
						this.activity_list_data[index].activity_id + 
						'&factory_id=' +
						this.activity_list_data[index].fac_info.id + 
						'&staff_id=' + 
						this.activity_list_data[index].id,
				})
			},
			
			//打开员工页面
			my(index) {
				console.log(this.activity_list_data[index],9999)
				if (this.activity_list_data[index].status == 2) {
					uni.showToast({
						title: '还未通过商家审核，请耐心等待',
						icon: 'none'
					})
					return false
				}
				uni.navigateTo({
					url: '../staff/staff_my?activity_id=' + 
						this.activity_list_data[index].activity_id + 
						'&factory_id=' +
						this.activity_list_data[index].fac_info.id + 
						'&staff_id=' + 
						this.activity_list_data[index].id,
				})
			},
			
			//先获取审核状态，打开管理页面
			mange(index) {
				if (this.activity_list_data[index].status != 1) {
					uni.showToast({
						title: '还未通过商家审核，请耐心等待',
						icon: 'none'
					})
					return false
				}
				uni.navigateTo({
					url: 'invitation?factory_id=' + 
					this.activity_list_data[index].fac_info.id + 
					'&activity_id=' + 
					this.activity_list_data[index].activity_id
				})
			},
		},
	}
</script>

<style lang="scss" scoped>
	@import '@/common/main.css';
	@import  '@/common/zcm-main.css';
	
	page {
		font-size: 30rpx;
		background-color: #F5F5F5;
	}

	.head {
		display: flex;
		justify-content: center;
		align-items: center;
		padding-top: 30rpx;

		.head-text {
			color: #ffffff;
			line-height: 2.5;
			background-color: #475dfc;
			width: 400rpx;
			text-align: center;
			border-radius: 50rpx;
			margin: 0rpx 15rpx 15rpx 15rpx;
		}
	}
	
	.staff {
		display: flex;
		flex-direction: row;
		align-items: center;
		margin-left: 50rpx;
		margin-top: 30rpx;
	
		.staff-em {
			height: 35rpx;
			width: 10rpx;
			background-color: #475dfc;
			border-radius: 50rpx;
		}
	
		.staff-text {
			font-weight: bold;
			margin-left: 10rpx;
		}
	}
	
	.box {
		background-color: #fff; 
		margin:20rpx 30rpx 20rpx 30rpx; 
		border-radius: 10rpx;
		padding: 3rpx 0 5rpx 0;
		box-shadow: 3rpx 3rpx #9B9B9B;
	}
	
	.contenttext {
		line-height: 45rpx;
		// font-size: 30rpx;
		overflow: hidden;
		/* break-all(允许在单词内换行。) */
		word-break: break-all;
		/* 超出部分省略号 */
		text-overflow: ellipsis;
		/** 对象作为伸缩盒子模型显示 **/
		display: -webkit-box;
		/** 设置或检索伸缩盒对象的子元素的排列方式 **/
		-webkit-box-orient: vertical;
		/** 显示的行数 **/
		-webkit-line-clamp: 1;
		
		text {
			font-weight: bold;
		}
	}
	
	.link {
		display: flex;
		padding: 15rpx 30rpx 0 30rpx;
		text-align: center;
	
		view {
			color: #475dfc;
			width: 50%;
		}
	}
	
	.top {
		position: relative;
		display: none;
		/* 先将元素隐藏 */
	}
	
	.topc {
		position: fixed;
		right: 0;
		// background: #F0F0F0;
		bottom: 105rpx;
		right: 10rpx;
		background-color: #FFF;
		border: solid 2rpx #475dfc;
		border-radius: 100rpx;
		height: 80rpx;
		width: 80rpx;
		line-height: 80rpx;
	}
	

</style>
